/*
* ============================================================================
*  Name        : sea_memtracker.h
*  Part of     : Finite state machine utilities
*  Description : Memory allocation tracker
*  Version     : %version: %
*  
*
* ============================================================================
*/
#if !defined( __sea_memtracker_h__ )
#define __sea_memtracker_h__

#include "sea_platform.h"

/**
 * @file sea_memtracker.h
 *
 * @ingroup DebugUtilities
 */

namespace sea
{
#if defined( DEBUG )

    /**
     * @class MemoryBlock sea_memtracker.h "sea_memtracker.h"
     * @brief Allocated memory block parameters
     *
     * @ingroup DebugUtilities
     */
    class MemoryBlock 
    {
    public:
        MemoryBlock( void* ptr, int size, int line, const char* file ):
            m_ptr( ptr ),
            m_size( size ),
            m_line( line ),
            m_file( file ) { }
        static void add( void* ptr, int size, int line, const char* file );
        static void remove( void* ptr );
        static bool print_stats( );

    public:
        static int m_allocations_counter;
        static int m_releases_counter;
        static long long m_max_memory_allocated;
        static long long m_total_memory_allocated;
        void* m_ptr;
        int m_size;
        int m_line;
        const char* m_file;

    private:
        static OsMutex m_lock;
    };
#endif
}

#endif // __sea_memtracker_h__
